﻿using System;
using System.IO;
using System.Reflection;
using Castle.ActiveRecord;
using Castle.ActiveRecord.Framework.Config;

namespace Hadlow.Jobvertizer.DbCreator
{
    /// <summary>
    /// This console program generates the schema for Jobvertizer using the ActiveRecordStarter
    /// class' CreateSchema method
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            string jobvertizerAssemblyPath = Path.Combine(
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                "Hadlow.Jobvertizer.dll");

            Assembly jobvertizerAsssembly = Assembly.LoadFile(jobvertizerAssemblyPath);
            Assembly[] assemblies = new Assembly[] { jobvertizerAsssembly };
            
            ActiveRecordStarter.Initialize(assemblies,
                new XmlConfigurationSource("ActiveRecord.config"));
            
            ActiveRecordStarter.CreateSchema();

            Console.WriteLine("Jobvertizer schema created successfully");
        }
    }
}
